import java.util.Scanner;
import java.util.Stack;

public class Main {
	
	private static String reverse(String str) {
		String result = "";
		Stack<Character> stack = new Stack<Character>();
		int i;
		
		for(i = 0; i < str.length(); i++)
			stack.push(str.charAt(i));
		
		while(!stack.isEmpty()) {
			result += stack.pop();
		}
		
		return result;
	}
	
	private static void daf(String input) {
		for(int i = 0; i < input.length(); i++) {
			if(input.charAt(i) == 'a') {
				if(i + 1 < input.length())
					input = input.substring(0, i + 1) + reverse(input.substring(i + 1, input.length()));
				continue;
			}
			
			if(input.charAt(i) == 'b') {
				if(i + 1 < input.length())
					input += input.substring(i + 1, input.length());
				continue;
			}
			
			if(input.charAt(i) == 'c') {
				if(i + 1 < input.length()) {
					String tmp = input.substring(i + 1, input.length());
					input = input.substring(0, i + 1);
					if(tmp.length() == 3)
						input += tmp.substring(1, tmp.length());
					else if(tmp.length() >= 4)
						input += tmp.substring(2, tmp.length());
				}
				continue;
			}
		}
		
		System.out.println(input);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String input;
		int n = Integer.parseInt(sc.nextLine());
		
		for(int i = 0; i < n; i++) {
			input = sc.nextLine();
			daf(input);			
		}
	}

}